class Payments < Application
  provides :xml, :js, :yaml
  
  def index
    @payments = Payment.find_by_category_id(params[:id])
    render @payments
  end
  
  def show
    @payment = Payment.find(params[:id])
    render @payment
  end
  
  def new
    only_provides :html
    @payment = Payment.new(params[:payment])
    @payment.category_id = params[:id]
    render
  end
  
  def create
    @payment = Payment.new(params[:payment])
    if @payment.save
      redirect url(:payment, @payment)
    else
      render :action => :new
    end
  end
  
  def edit
    only_provides :html
    @payment = Payment.find(params[:id])
    render
  end
  
  def update
    @payment = Payment.find(params[:id])
    if @payment.update_attributes(params[:payment])
      redirect url(:payment, @payment)
    else
      raise BadRequest
    end
  end
  
  def destroy
    @payment = Payment.find(params[:id])
    if @payment.destroy
      redirect url(:payments)
    else
      raise BadRequest
    end
  end
end